package com.wodsy.phoenix.datadao.shopc.dao.impl;

import com.wodsy.phoenix.datadao.base.BaseHibernateDao;
import com.wodsy.phoenix.datadao.shopc.dao.ShopkeeperRecommendGoodsDao;
import com.wodsy.phoenix.dataobject.shopc.model.ShopkeeperRecommendGoods;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("shopkeeperRecommendGoodsDao")
public class ShopkeeperRecommendGoodsDaoImpl extends BaseHibernateDao<ShopkeeperRecommendGoods, Integer> implements ShopkeeperRecommendGoodsDao {
	@Autowired
	@Qualifier(value="shopc")
	@Override
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public Class<ShopkeeperRecommendGoods> getModelClass() {
		return ShopkeeperRecommendGoods.class;
	}

	@Override
	public List<ShopkeeperRecommendGoods> findGoodRecommends(Integer shopId) {
		Criteria criteria = getSession().createCriteria(getModelClass());
		criteria.add(Restrictions.eq("shopId", shopId));
		criteria.addOrder(Order.desc("weight"));
		criteria.addOrder(Order.desc("operTime"));
		return criteria.list();
	}

}
